package com.yc.bdw.Activity;

import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.yc.bdw.Adapter.SeckillListAdapter;
import com.yc.bdw.R;
import com.yc.bdw.model.Product;

import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.ui.BindView;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class SeckillActivity extends KJActivity{
    @BindView(id = R.id.seckill_back, click = true)
    private ImageView backBtn;
    @BindView(id = R.id.seckill_rule, click = true)
    private TextView ruleText;
    @BindView(id = R.id.seckill_time1, click = true)
    private TextView Time1Text;
    @BindView(id = R.id.seckill_time2, click = true)
    private TextView Time2Text;
    @BindView(id = R.id.seckill_time3, click = true)
    private TextView Time3Text;
    @BindView(id = R.id.seckill_time4, click = true)
    private TextView Time4Text;
    @BindView(id = R.id.seckill_endtime_hour)
    private TextView hourText;
    @BindView(id = R.id.seckill_endtime_minute)
    private TextView minuteText;
    @BindView(id = R.id.seckill_endtime_second)
    private TextView secondText;

    @BindView(id = R.id.seckill_commodities, click = true)
    private ListView commoditiesList;

    private List<Product> products = new ArrayList<Product>();
    private SeckillListAdapter adapter;

    private Handler handler = new Handler();

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_seckill);
    }

    @Override
    public void initData() {
        super.initData();

        init();

        adapter = new SeckillListAdapter(aty);
        adapter.setList(products);

        handler.postDelayed(runnable, 1000);
    }
    private void init() {
        Product item = new Product();
        item.setPrice(BigDecimal.valueOf(11));
        item.setSoldPercentage("2%");
        item.setName("酒");
        products.add(item);

        Product item2 = new Product();
        item2.setPrice(BigDecimal.valueOf(22));
        item2.setSoldPercentage("99%");
        item2.setName("酒2");
        products.add(item2);

        Product item3 = new Product();
        item3.setPrice(BigDecimal.valueOf(33));
        item3.setName("酒3");
        item3.setSoldPercentage("45%");
        products.add(item3);

        Product item4 = new Product();
        item4.setPrice(BigDecimal.valueOf(44));
        item4.setName("酒4");
        item4.setSoldPercentage("32%");
        products.add(item4);
    }


    @Override
    public void initWidget() {
        super.initWidget();

        commoditiesList = (ListView) findViewById(R.id.seckill_commodities);
        commoditiesList.setAdapter(adapter);
        commoditiesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                showActivity(aty,DetailActivity.class);
            }
        });
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            case R.id.seckill_back:
                finish();
                break;
            case R.id.seckill_time1:
                break;
            case R.id.seckill_time2:
                break;
            case R.id.seckill_time3:
                break;
            case R.id.seckill_time4:
                break;
            case R.id.seckill_rule:
                break;
        }
    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            handler.postDelayed(this, 1000);
        }
    };
}
